import { createRouter, createWebHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';

const token = localStorage.getItem("token");

// 三级路由
export const CHILDROUTERS: RouteRecordRaw[] = [];

// 二级路由
export const CHILDROUTER: RouteRecordRaw[] = [
    {
        path: '/home',
        meta: {
            title: '首页',
            icon: ''
        },
        component: () => import('../views/home/IndexView.vue'),
        children: CHILDROUTERS
    },
    {
        path: '/circle',
        meta: {
            title: '病友圈123',
            icon: ''
        },
        component: () => import('../views/circle/IndexView.vue')
    },
    {
        path: '/sousuo',
        meta: {
            title: '病友圈搜索页',
            icon: ''
        },
        component: () => import('@/views/sousuo/IndexView.vue')
    },
    {
        path: '/video',
        meta: {
            title: '视频',
            icon: ''
        },
        component: () => import('@/views/video/IndecView.vue')
    }
];

// 一级路由
export const PATHROUTER: RouteRecordRaw[] = [
    {
        path: '/layout',
        meta: {
            title: '首页'
        },
        component: () => import('../views/layout/IndexView.vue'),
        redirect: '/home',
        children: CHILDROUTER
    },
    {
        path: '/login',
        meta: {
            title: '登录'
        },
        component: () => import('../views/login/IndexView.vue')
    },
    {
        path: '/zhuce',
        meta: {
            title: '注册'
        },
        component: () => import('../views/zhuce/IndexView.vue')
    },
    {
        path: '/passwordone',
        meta: {
            title: '忘记密码一'
        },
        component: () => import('../views/passwordone/IndexView.vue')
    },
    {
        path: '/passwordtwo',
        meta: {
            title: '忘记密码二'
        },
        component: () => import('../views/passwordtwo/IndexView.vue')
    },
    {
        path: '/setting',
        meta: {
            title: '设置',
            icon: ''
        },
        component: () => import('@/views/setting/IndexView.vue')
    },
    {
        path: '/userchild',
        meta: {
            title: '个人信息设置',
            icon: ''
        },
        component: () => import('@/views/userchild/IndexView.vue')
    },
    {
        path: '/xgpwd',
        meta: {
            title: '修改密码',
            icon: ''
        },
        component: () => import('@/views/xgpwd/IndexView.vue')
    },
    {
        path: '/bbjce',
        meta: {
            title: '版本检测',
            icon: ''
        },
        component: () => import('@/views/bbjce/IndexView.vue')
    },
    {
        path: '/pmldu',
        meta: {
            title: '屏幕亮度',
            icon: ''
        },
        component: () => import('@/views/pmldu/IndexView.vue')
    },
    {
        path: '/invitefriend',
        meta: {
            title: '邀请好友',
            icon: ''
        },
        component: () => import('@/views/invitefriend/IndexView.vue')
    },
    {
        path: '/my',
        meta: {
            title: '个人中心',
            icon: ''
        },
        component: () => import('../views/my/IndexView.vue'),
        children: CHILDROUTER,
        beforeEnter: (to, from, next) => {
            if (token) {
                next();
            } else {
                next('/login');
            }
        }
    },
    {
        path: '/my_message',
        meta: {
            title: '我的消息'
        },
        component: () => import('../views/my_message/IndexView.vue')
    },
    {
        path: '/yspj/:doctorId',
        name: 'yspj',
        component: () => import('../views/yspj/IndexView.vue')
    },
    {
        path: '/system_meg',
        meta: {
            title: '系统消息'
        },
        component: () => import('../views/System_meg/IndexView.vue')
    },
    {
        path: '/syxq',
        name: 'syxq',
        component: () => import('../views/syxq/IndexView.vue')
    },
    {
        path: '/sedic_meg',
        meta: {
            title: '问诊消息'
        },
        component: () => import('../views/Sedic_meg/IndexView.vue')
    },
    {
        path: '/video_money',
        meta: {
            title: '购买',
            icon: ''
        },
        component: () => import('../views/video_money/IndexView.vue')
    },
    {
        path: '/sou',
        meta: {
            title: '搜索'
        },
        component: () => import('../views/sou/indexView.vue')
    },
    {
        path: '/zhi',
        name: 'zhi',
        component: () => import('../views/zhi/indexView.vue')
    },
    {
        path: '/bing',
        meta: {
            title: '病症'
        },
        component: () => import('../views/bing/indexView.vue')
    },
    {
        path: '/jieguo',
        meta: {
            title: '病友圈搜索结果',
            icon: ''
        },
        component: () => import('../views/jiguo/IndexView.vue')
    },
    {
        path: '/youdetail/:sickCircleId',
        name: 'youdetail',
        component: () => import('../views/youdetail/IndexView.vue')
    },
    {
        path: '/youdeails',
        name: '病友圈搜索详请页',
        component: () => import('../views/youdeails/IndexView.vue')
    },
    {
        path: '/mybyq',
        meta: {
            title: '我的病友圈噢噢噢噢噢噢噢噢也',
            icon: ''
        },
        component: () => import('../views/mybyq/IndexView.vue'),
        props: true
    },
    {
        path: '/yhxx/:id/:name',
        meta: {
            title: '病友圈用户信息'
        },
        component: () => import('@/views/yhxx/IndexView.vue'),
        props: true
    },
    {
        path: '/yhxx2',
        meta: {
            title: '病友圈用户信息1'
        },
        component: () => import('../views/yhxx2/IndexView.vue'),
        props: true
    },
    {
        path: '/fabiao',
        meta: {
            title: '病友圈发表',
            icon: ''
        },
        component: () => import('../views/fabiao/IndexView.vue')
    },
    {
        path: '/money',
        meta: {
            title: '钱包',
            icon: ''
        },
        component: () => import('../views/money/IndexView.vue')
    },
    {
        path: '/recharge',
        meta: {
            title: '充值',
            icon: ''
        },
        component: () => import('../views/recharge/IndexView.vue')
    },
    {
        path: '/rechargeok',
        meta: {
            title: '充值成功',
            icon: ''
        },
        component: () => import('../views/rechargeok/IndexView.vue')
    },
    {
        path: '/reflect',
        meta: {
            title: '提现',
            icon: ''
        },
        component: () => import('../views/reflect/IndexView.vue')
    },
    {
        path: '/reflectlist',
        meta: {
            title: '提现记录',
            icon: ''
        },
        component: () => import('../views/reflectlist/IndexView.vue')
    },
    {
        path: '/HTiXian',
        meta: {
            title: 'H提现',
            icon: ''
        },
        component: () => import('../views/HTiXian/IndexView.vue')
    },
    {
        path: '/recognize_bank',
        meta: {
            title: '银行卡识别',
            icon: ''
        },
        component: () => import('../views/recognize_bank/Indexview.vue')
    },
    {
        path: '/bound_bank',
        meta: {
            title: '绑定银行卡',
            icon: ''
        },
        component: () => import('../views/bound_bank/IndexView.vue')
    },
    {
        path: '/Bank_message',
        meta: {
            title: '查看银行卡',
            icon: ''
        },
        component: () => import('../views/Bank_message/IndexView.vue')
    },
    {
        path: '/my_file',
        meta: {
            title: '我的档案',
            icon: ''
        },
        component: () => import('../views/my_file/IndexView.vue')
    },
    {
        path: '/my_file_add',
        meta: {
            title: '我的档案添加',
            icon: ''
        },
        component: () => import('../views/my_file_add/IndexView.vue')
    },
    {
        path: '/nickname',
        meta: {
            title: '修改昵称',
            icon: ''
        },
        component: () => import('../views/nickname/IndexView.vue')
    },
    {
        path: '/xgsex',
        meta: {
            title: '修改性别'
        },
        component: () => import('../views/xgsex/IndexView.vue')
    },
    {
        path: '/xgtizheng',
        meta: {
            title: '修改体征'
        },
        component: () => import('../views/xgtizheng/IndexView.vue')
    },
    {
        path: '/chat_service',
        meta: {
            title: '聊天客服'
        },
        component: () => import('../views/chat_service/IndexView.vue')
    },
    {
        path: '/zhidetail/:id',
        name: 'zhidetail',
        component: () => import('../views/zhidetail/IndexView.vue')
    },
    {
        path: '/pllb',
        meta: {
            title: '评论列表'
        },
        component: () => import('../views/pllb/IndexView.vue')
    },
    {
        path: '/my_follow',
        meta: {
            title: '我的关注',
            icon: ''
        },
        component: () => import('../views/my_follow/IndexView.vue')
    },
    {
        path: '/my_collect',
        meta: {
            title: '我的收藏'
        },
        component: () => import('../views/my_collect/IndexView.vue')
    },
    {
        path: '/my_renwu',
        meta: {
            title: '我的任务',
            icon: ''
        },
        component: () => import('@/views/my_renwu/IndecView.vue')
    },
    {
        path: '/my_file_edit',
        meta: {
            title: '我的档案修改',
            icon: ''
        },
        component: () => import('../views/my_file_edit/Indexview.vue')
    },
    {
    path: '/my_follow_details',
        meta: {
            title: '我的关注详情',
            icon: ''
        },
        component: () => import('../views/my_follow_details/Indexview.vue')
    },
    {
        path: '/shoudetail/:id',
        name: 'shoudetail',
        component: () => import('../views/shoudetail/IndexView.vue')
    },
    {
        path: '/dqwz',
        meta: {
            title: '当前问诊123',
            icon: ''
        },
        component: () => import('../views/dqwz/IndexView.vue')
    },
    {
        path: '/opinio',
        name: '被采纳意见',
        component: () => import('../views/opinio/IndexView.vue')
    },
    {
        path: '/clinical',
        name: '医生评论',
        component: () => import('../views/clinical_history/IndexView.vue')
    },
    {
        path: '/chinical_money',
        name: '医生评论完成，送礼物 ',
        component: () => import('../views/chinical_money/IndexView.vue')
    },
    {
        path: '/zixu',
        name: 'zixu',
        component: () => import('../views/zixu/IndexView.vue')
    },
    {
        path: '/yis',
        name: 'yis',
        component: () => import('../views/yis/IndexView.vue')
    },
    {
        path: '/ChatRoom',
        name: 'ChatRoom',
        component: () => import('../views/ChatRoom/IndexView.vue')
    },
    {
        path: '/yisdetail/:doctorId',
        name: 'yisdetail',
        component: () => import('../views/yisdetail/IndexView.vue')
    },
    {
        path: "/authentication",
        name: "实名认证",
        component: () => import('../views/authentication/indexView.vue')
    },
    {
        path: "/authenticationok",
        name: "实名认证成功",
        component: () => import('../views/authenticationok/indexView.vue')
    },
    {
        path: '/my_video',
        meta: {
            title: '购买的视频',
            icon: ''
        },
        component: () => import('@/views/my_video/IndexView.vue')
    },
    {
        path: '/xnlb',
        meta: {
            title: '虚拟列表',
            icon: ''
        },
        component: () => import('@/views/XNlb/index.vue')
    },
    {
        path: '/yswz',
        name: 'yswz',
        component: () => import('@/views/yswz/IndexView.vue')
    },
    {
        path: '/',
        name: '引导页',
        component: () => import('../views/start/IndexView.vue')
    }
];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: PATHROUTER
});

// 路由守卫
const whiteList = ['/login', '/home', '/zhuce', '/', '/passwordone', '/passwordtwo', '/404'];
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem("result");
    if (whiteList.indexOf(to.path)!== -1) {
        next();
    } else {
        if (!token && to.path!== "/login") {
            next("/login");
        } else {
            next();
        }
    }
});

export default router;
